#include "Comm.hpp"
#include <unistd.h>
#include "Fifo.hpp"
int main()
{
    key_t key = GetShmKeyOrDie();
    cout << key << endl;

    int shmid = GetShm(key, defaultsize);
    cout << "shmid: " << shmid << endl;

    char *addr = (char *)ShmAttch(shmid);
    cout << "shmat success " << shmid << endl;
    // sleep(2);

    cout << "shmdt success " << shmid << endl;
    // sleep(5);

    Sync syn;
    syn.OpenWriteOrDie();

    // 挂接后即可进行通信
    memset(addr, 0, defaultsize);
    for (char c = 'a'; c <= 'z'; c++)
    {
        addr[c - 'a'] = c;
        sleep(1);
        syn.Wakeup();
    }

    //撤销关联
    ShmDetach(addr);
    
    //删除共享内存
    DeleteShm(shmid);
    return 0;
}